package org.fuys.coder.domain.auth.service.common.register.impl;

import org.fuys.coder.common.exception.handler.NeedCallBackException;
import org.fuys.coder.infrastructure.model.dto.UserDTO;
import org.fuys.coder.domain.auth.model.req.CommonRegisterReq;
import org.fuys.coder.domain.auth.repository.ICommonRepository;
import org.fuys.coder.domain.auth.service.common.register.ICommonRegisterService;
import org.fuys.coder.domain.auth.service.handler.register.RegisterHandlerChain;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.domain.auth.service.common.register.impl
 * @className: ICommonRegisterServiceImpl
 * @author: WangJing
 * @description: 普通用户注册实现类
 * @date: 2024/6/18 20:13
 * @version: 1.0
 */
@Service
public class ICommonRegisterServiceImpl implements ICommonRegisterService {

    @Resource
    private ICommonRepository commonAuthRepository;

    @Resource
    private RegisterHandlerChain registerHandlerChain;

    @Override
    @Transactional(rollbackFor = NeedCallBackException.class)
    public boolean register(CommonRegisterReq req) {
        UserDTO userDTO=new UserDTO();
        userDTO.setEmail(req.getEmail());
        userDTO.setPassword(req.getPassword());
        userDTO.setUsername(req.getUsername());
        userDTO.setCode(req.getCode());
        //之后在链路中添加审核用户名的处理
        return registerHandlerChain.doHandle(userDTO);
    }
}
